<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
	<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
	<meta HTTP-EQUIV="Expires" CONTENT="0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试结果查询</title>
<style type="text/css">
	@import "../dojo-release-1.5.0/dijit/themes/tundra/tundra.css";
	@import "../dojo-release-1.5.0/dojo/resources/dojo.css";
	@import "../dojo-release-1.5.0/dojox/grid/resources/tundraGrid.css";
</style>
<script type="text/javascript" src="../dojo-release-1.5.0/dojo/dojo.js" djConfig="parseOnLoad:true"></script>
<script type="text/javascript" src="../framework/uiutil.js"></script>
<script type="text/javascript">
dojo.addOnLoad(function(){
	initProductSelect();
	initTestorSelect();
	dojo.connect(dojo.byId("productSelect"),"onblur",initSuiteSelect);
});


//初始化产品选择列表
function initProductSelect(){
	dojo.xhrGet({
		 url:"../bkgrd/getProductList.do",
		 handleAs:"json",
		 load:function(response){
			 ps = [];
			 for(var i in response){
				 ps.push({value:response[i],name:response[i]});
			 }
			 D.initCombo("productSelect",ps)
		 }
	});
}

//初始化检测员选择列表
function initTestorSelect(){
	dojo.xhrGet({
		 url:"../bkgrd/getAllTestorList.do",
		 handleAs:"json",
		 preventCache:true,
		 load:function(response){
			 ps = [];
			 for(var i in response){
				 ps.push({value:response[i],name:response[i]});
			 }
			 D.initCombo("testorSelect",ps)
		 }
	});
}


//初始化测试项
function initSuiteSelect(){
	var productName = D.getComboValue("productSelect");
	dojo.xhrPost({
		 url:"../bkgrd/getSuiteList.do",
		 content:{productName:productName},
		 handleAs:"json",
		 preventCache:true,
		 load:function(response){
			 ps = [];
			 for(var i in response){
				 ps.push({value:response[i],name:response[i]});
			 }
			 D.initCombo("suiteSelect",ps)
		 }
	});
}

var dataIdScope = [];	//当前数据ID范围[start,end]
function query(startId,endId){
	if(!dijit.byId("productSelect").isValid() ||
		!dijit.byId("startDate").isValid() ||
		!dijit.byId("endDate").isValid()){
		alert("请至少选择产品类型和检测时间范围");
		return;
	}
	var suiteName =  D.getComboValue("suiteSelect");
	var testor = D.getComboValue("testorSelect");
	var productName = D.getComboValue("productSelect");
	var barCode = dojo.byId("barCode").value;
	var idCode = dojo.byId("idCode").value;
	var startDate = D.getWholeDateTime('startDate',null);
	var endDate = D.getWholeDateTime('endDate',null);
	var result = D.getComboValue("resultSelect");
	
	dojo.xhrPost({
		 url:"../bkgrd/queryProductSuite.do",
		 encoding : 'UTF-8',
		 content:{
			 suiteName:suiteName,
			 testor:testor,
			 productName:productName,
			 barCode:barCode,
			 idCode:idCode,
			 startDate:startDate.getTime(),
			 endDate:endDate.getTime(),
			 result:result,
			 
			 startId:startId,
			 endId:endId
		 },
		 preventCache:true,	 
		 handleAs:"json",
		 load:function(response){
			if(response == ""){
				alert("没有结果，请检查查询条件。");
				return;
			}
			displayResult(response);
		 }
	});
}

function moveBefore(){
	query(-1,dataIdScope[0]);
}

function moveNext(){
	query(dataIdScope[1],-1);
}

function displayResult(resultList){
	dataIdScope[0] = resultList[0]["id"];
	dataIdScope[1] = resultList[resultList.length-1]["id"];
	D.fillTableData("testSuiteTable",resultList);
}

//追溯详细检测报告
function retrospect(){
	var item = D.getSelectedRowOfTable("testSuiteTable")[0];
	if(item == null){
		alert("请至少选择表格中的一行");
	}
	window.open("testResultRetrospect.html?productName="+item["productName"]+"&idCode="+item["idCode"]);
}

</script>

<style type="text/css">
#testSuiteTable{
	border:1px solid #333;
	width:100%;
	margin:10px;
	height:500px;
	font-size:0.9em;
}
</style>
</head>
<body class="tundra">

<table width="100%">
<tr><td>请选择产品类型：</td><td><select dojoType="dijit.form.FilteringSelect" id="productSelect" value=""></select></td>
<td>产品标识码（如MAC）：</td><td><input type="text" dojoType="dijit.form.TextBox" id="idCode" size="30" trim="true" value=""/></td></tr>
<tr><td>请选择测试项：</td><td><select dojoType="dijit.form.FilteringSelect" id="suiteSelect" value="" required="false"></select></td>
<td>扫描条码：</td><td><input type="text" dojoType="dijit.form.TextBox" id="barCode" size="30" trim="true" value=""/></td></tr>
<tr><td>测试人员：</td><td><select dojoType="dijit.form.FilteringSelect" id="testorSelect" value=""  required="false"></select></td>
<td>检测结果：</td><td>
<select dojoType="dijit.form.FilteringSelect" id="resultSelect" value=""  required="false">
	<option value="" selected="selected">全部</option>
	<option value="PASS">检测通过</option>
	<option value="FAIL">检测不通过</option>
</select></td></tr>
<tr><td>测试时间：</td><td colspan="3">
<input type="text" id="startDate"  dojoType="dijit.form.DateTextBox" required="true" onchange="endDate.focus()"/>&nbsp;至&nbsp;
<input type="text" id="endDate" dojoType="dijit.form.DateTextBox" required="true"/>
</td></tr>
<tr><td colspan="4" align="center">
<button dojoType="dijit.form.Button" id="query" onclick="query(0,-1);">查询检测结果</button>
<button dojoType="dijit.form.Button" id="retrospect" onclick="retrospect()">详细检测报告</button>

</td></tr>
</table>
<table><tr><td>
<button dojoType="dijit.form.Button" onclick="moveBefore()">&lt;&lt;</button>
<button dojoType="dijit.form.Button" onclick="moveNext()">&gt;&gt;</button>
</td></tr></table>
<div>
<table dojoType="dojox.grid.DataGrid" id="testSuiteTable"  autoWidth="true">
 <thead>
	<tr>
	     <th field="productName" width="150px">产品</th>
	     <th field="idCode" width="120px">产品标识码</th>
	     <th field="barCode" width="120px">条码</th>
	     <th field="suiteName" width="120px">测试项</th>
	     <th field="testTime" width="150px">测试时间</th>
	     <th field="testor" width="100px">检测人员</th>
	     <th field="result" width="50px">检测结果</th>
	</tr>
</thead>
</table>
</div>


</body>
</html>